<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>
<body>
	<div>
		<button onclick="quan(1)">全选</button>
		<button onclick="quan(2)">取消全选</button>
		<button onclick="quan(3)">反选</button>
		<button onclick="add()">添加</button>
		<hr>
		<input type="checkbox" name="">语文 <br>
		<input type="checkbox" name="">语文 <br>
		<input type="checkbox" name="">语文 <br>
		<input type="checkbox" name="">语文 <br>
		<input type="checkbox" name="">语文 <br>
		<input type="checkbox" name="">语文 <br>
		<input type="checkbox" name="">语文 <br>
		<input type="checkbox" name="">语文 <br>
		<input type="checkbox" name="">语文 <br>
		<input type="checkbox" name="">语文 <br>
	</div>
	<script type="text/javascript">
		//获取所有input
		let input = document.getElementsByTagName("input")
		function quan(val){
			for (let i = 0; i < input.length; i++){
				if (val == 1) {
					input[i].checked = true
				}else if (val == 2) {
					input[i].checked = false
				}else{
					input[i].checked = !input[i].checked
				}
			}

		}
		function add(){
			let arr = ['高数','线代','概率论','复变函数','java','vue']
			// let inp = document.createElement('input')
			// inp.type = "checkbox"
			// let span = document.createElement('span')
			// span.innerText = arr[parseInt(Math.random() * arr.length)]
			// let br = document.createElement('br')
			 let div = document.getElementsByTagName('div')[0]
			// div.appendChild(inp)
			// div.appendChild(span)
			// div.appendChild(br)

			let pp = document.createElement('div')
			pp.innerHTML = '<input type="checkbox">' + arr[parseInt(Math.random() * arr.length)]
			div.appendChild(pp)
		}
	</script>
</body>
</html>